//
//  ASTeacherCallNameConfirmViewController.m
//  AttendenceSys
//
//  Created by ld on 16/1/28.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASTeacherCallNameConfirmViewController.h"

@interface ASTeacherCallNameConfirmViewController ()

@end

@implementation ASTeacherCallNameConfirmViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initData];
    [self initView];
    
    // Do any additional setup after loading the view.
}

-(void)initData
{
    _teaCallNameInfoArr = [[NSMutableArray alloc] init];
    
    SubClassInfo* info = [[SubClassInfo alloc] init];
    info.subOrClassContent = @"王岳伦";
    info.isSelect = NO;
    [_teaCallNameInfoArr addObject:info];
    
    SubClassInfo* info1 = [[SubClassInfo alloc] init];
    info1.subOrClassContent = @"张小艾";
    info1.isSelect = NO;
    [_teaCallNameInfoArr addObject:info1];
    
    SubClassInfo* info2 = [[SubClassInfo alloc] init];
    info2.subOrClassContent = @"李平";
    info2.isSelect = NO;
    [_teaCallNameInfoArr addObject:info2];
    
    SubClassInfo* info3 = [[SubClassInfo alloc] init];
    info3.subOrClassContent = @"张明";
    info3.isSelect = NO;
    [_teaCallNameInfoArr addObject:info3];
    
    SubClassInfo* info4 = [[SubClassInfo alloc] init];
    info4.subOrClassContent = @"窦B";
    info4.isSelect = NO;
    [_teaCallNameInfoArr addObject:info4];
    
    SubClassInfo* info5 = [[SubClassInfo alloc] init];
    info5.subOrClassContent = @"孙亮";
    info5.isSelect = NO;
    [_teaCallNameInfoArr addObject:info5];
    
    SubClassInfo* info6 = [[SubClassInfo alloc] init];
    info6.subOrClassContent = @"王峰";
    info6.isSelect = NO;
    [_teaCallNameInfoArr addObject:info6];
    
    SubClassInfo* info7 = [[SubClassInfo alloc] init];
    info7.subOrClassContent = @"柳红兵";
    info7.isSelect = NO;
    [_teaCallNameInfoArr addObject:info7];
}

-(void)initView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.frame = CGRectMake(0, 10, self.view.frame.size.width, self.view.frame.size.height);
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.scrollEnabled = YES;
    [_tableView registerClass:[TeacherCallNameConfirmCell class] forCellReuseIdentifier:NSStringFromClass([TeacherCallNameConfirmCell class])];
    [self.view addSubview:_tableView];
    
    //存储
    UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, CallNameCellHeight*_teaCallNameInfoArr.count, CGRectGetWidth(self.view.bounds), 100)];
    footer.backgroundColor = [UIColor clearColor];
    
    UIButton* saveBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    saveBtn.frame = CGRectMake(50, 50,[UIScreen mainScreen].bounds.size.width-50*2,50);
    [saveBtn setTitle:@"开始点名" forState:UIControlStateNormal];
    saveBtn.layer.cornerRadius = 4.5;
    [saveBtn addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    saveBtn.backgroundColor = RGB(252, 120, 61);
    saveBtn.enabled = YES;
    [footer addSubview:saveBtn];
    _tableView.tableFooterView = footer;
    
}

-(void)save
{

}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_teaCallNameInfoArr count];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TeacherCallNameConfirmCell* cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([TeacherCallNameConfirmCell class])];
    [cell setBackgroundColor:[UIColor whiteColor]];
    SubClassInfo* subOrClaInfo =  [_teaCallNameInfoArr objectAtIndex:indexPath.row];
    cell.callNameBtn.tag =indexPath.row + CallNameTag;
    [cell setselectCallName:subOrClaInfo.isSelect];
    cell.delegate = self;
    cell.nameLab.text = subOrClaInfo.subOrClassContent;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return CallNameCellHeight;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    [self getIsSelect:indexPath.row];
    
}

-(void)getIsSelect:(NSInteger)index
{
    SubClassInfo* subclaInfo = [_teaCallNameInfoArr objectAtIndex:index];
    subclaInfo.isSelect = !subclaInfo.isSelect;
    
    NSIndexPath* indexPath = [NSIndexPath indexPathForRow:index inSection:0];
    [_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}

-(void)callName
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
